Repository navigation
DEV-1262: while streaming, complete the command in flight only on its own in-stream reply - #330
Merged
Merged
Conversation
While streaming, the branch of processPacket() for an in-stream response (FF 8A ...) cancelled the ACK timer, cleared the wait flags, removed the head of the instruction queue and unlocked it, whatever the response was. The firmware also sends a status response unprompted (dock, undock, the user button, a low-battery stop). So such a push removed a SET command still waiting for its ACK, or a queued instruction not yet sent, and the next ACK was matched to the wrong instruction: for startSDLogging(), processAckFromSetCommand(SET_RWC) against START_LOGGING_ONLY's one-byte instruction. The branch now reads the response opcode first and completes the command in flight only if the opcode is that command's expected response (mBtGetCommandMap), as the protocol says (log-and-stream-common docs/SHIMMER3_BT_COMMUNICATION_PROTOCOL.md section 5.4, rule 2). Any other response is still processed, but leaves the queue, the wait flags and the ACK timer alone. processInstreamResponse(boolean) still reads the opcode itself and hands it to the new processInstreamResponse(byte, boolean), which holds the unchanged parsing, so overrides and other callers keep working. API_00030 (9 tests, CRC off/1/2) covers a status push while a SET command awaits its ACK, while a GET command awaits its reply, and with nothing in flight. All 9 fail without the fix. ShimmerDriver and ShimmerDriverPC test suites pass. The Android half is ShimmerResearch/ShimmerAndroidAPI#122 (DEV-1149). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes DEV-1262. This is the driver half of DEV-1149, whose Android half is ShimmerResearch/ShimmerAndroidAPI#122.
Defect
While streaming, the branch of
ShimmerBluetooth.processPacket()that handles an in-stream response (DATA … FF 8A <opcode> …) did four things, whatever the response was:mWaitForAckandmWaitForResponse;removeInstruction(0);The firmware also sends a status response unprompted: on a dock or undock, the user button, a trial-duration expiry or a low-battery stop. When one of these arrived:
startSDLogging()(SET_RWC, thenSTART_LOGGING_ONLY), that meansprocessAckFromSetCommand(SET_RWC)runs againstSTART_LOGGING_ONLY's one-byte instruction;The protocol matches a reply to its command by the response opcode, never by the ACK: log-and-stream-common
docs/SHIMMER3_BT_COMMUNICATION_PROTOCOL.md, section 5.4, rule 2.Fix
mBtGetCommandMap(isReplyToCommandInFlight()).processInstreamResponse(boolean)keeps its signature. It reads the opcode and hands it to a newprocessInstreamResponse(byte, boolean), which holds the unchanged parsing. Subclass overrides and the other caller (the not-streaming path) keep working. ShimmerAndroidAPI'sShimmeroverrides the boolean version.Tests
New
API_00030_StreamingInstreamResponseQueueTest(9 tests) inShimmerDriverPC:SET_RWCawaits its ACK (startSDLogging())SET_RWCand leavesSTART_LOGGING_ONLYqueuedGET_VBATTawaits its replyGET_VBATTkeeps waiting; its own reply then completes it and the battery is parsedGET_VBATTqueuedGET_VBATTstays queuedEach scenario also checks that the push itself is still processed: its docked bit takes effect.
ShimmerDrivergradlew testShimmerDriverPCgradlew testNot run on hardware. The Android HIL (ShimmerAndroidAPI#128) can cover this over BLE once an Android build uses a driver with this fix.
The same rule in the other implementations
comms/radioProtocol/LiteProtocol(in-stream branch of its packet parser)CommsProtocolRadio, which Consensys uses only for non-Shimmer3 devices (Sweatch, Shimmer4 SDK); Shimmer3 units go throughShimmerPCMSS→ShimmerBluetooth. Worth its own change if that path is still wantedShimmer.java's own parser)Shimmer3BLEAndroid)0xFFresolves the awaited ACK, if a SET is sent while streamingGetStatusCommandis in flight, with a test. A residual risk exists only with the ACK prefix left onRelease
Not urgent for Android 3.2.11_beta. It reaches each consumer as follows:
🤖 Generated with Claude Code